package org.sjm.samples.dao;

import java.util.List;

import org.sjm.samples.model.UserSubject;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class UserSubjectDAOImpl extends BaseHibernateDAO<UserSubject> implements IUserSubjectDAO {

	@Override
	public List<UserSubject> FindAllUserSubjects() {
		return this.find("FROM UserSubject");
	}

	@Override
	public void deleteUserSubjectBySubId(Integer subId) {
		List<UserSubject> userSubject = getUserSubjectsBySubId(subId);
		if(userSubject != null){
			this.deleteAll(userSubject);
		}
	}

	@Override
	public List<UserSubject> getUserSubjectsBySubId(Integer subId) {
		return this.queryForList("FROM UserSubject AS us WHERE us.subject.subId=? ", new Object[]{subId});
	}

}
